<?php

$order = $_SESSION['paging'][$path_string]['order'];
$filter = isset($_SESSION['paging'][$path_string]['filter']) ? '%' . $_SESSION['paging'][$path_string]['filter'] . '%' : '%';


$sql = $db->select()
   ->from(array('r' => 'shop_ranges'), '*')
   ->order($order)
   ->where($db->quoteInto('r.site_id=?', $site['id']))
   ->where($db->quoteInto('title LIKE ?', $filter))
;

$ranges = $db->fetchAll($sql);


$page   = $_SESSION['paging'][$path_string]['page'];
$show   = $_SESSION['paging'][$path_string]['show'];
$offset = ($page - 1) * $show;
$total  = count($ranges);
#
$smarty->assign('order', $order);
$smarty->assign('page', $page);
$smarty->assign('show', $show);
$smarty->assign('filter', $filter);
$smarty->assign('offset', $offset);
$smarty->assign('total', $total);

$ranges = array_slice($ranges, $offset, $show);

$smarty->assign('ranges', $ranges);

if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
	header('Content-type: text/xml');
	$smarty->display('shop/ranges/index.tpl.taconite');
} else {
	$smarty->display('shop/ranges/index.tpl.html');
}